/**
 * @author guocailee
 */
import 'normalize.css'
import 'font-awesome-webpack'
import 'styles/app.scss'

import Vue from 'vue'
import VueRouter from 'vue-router'
import VueResource from 'vue-resource'
import fetch from 'src/utils/fetch'
import upload from 'src/utils/upload'

import VueValidator from 'vue-validator'
import validatorRule from 'src/config/validator'

import Vuex from 'vuex'
import { sync } from 'vuex-router-sync'

// filter import
import moment from 'src/utils/moment.filter'
import dictionary from 'src/utils/dictionary.filter'

import store from 'src/store'

import routerMap from './app.router'

import theme from 'components/theme/'
import { checkIsLogin } from 'src/store/actions/user'
import { getUserInfo } from 'src/store/actions/info'
import { getQuestionList, getUserSecurityQuestion } from 'src/store/actions/security'

/* eslint-disable no-new */
Vue.use(VueValidator)
Vue.use(validatorRule)

/**
 * global theme component
 */
Vue.use(theme)

Vue.use(VueResource)
Vue.use(fetch)
Vue.use(upload)

/**
 * use Filter
 */
Vue.use(moment)
Vue.use(dictionary)

Vue.use(VueRouter)
Vue.use(Vuex)

var router = new VueRouter()
sync(store, router)
var App = {
  el: '',
  store,
  vuex: {
    actions: {
      checkIsLogin,
      getUserInfo,
      getQuestionList,
      getUserSecurityQuestion
    }
  },
  ready() {
    this.getUserInfo()
    this.getQuestionList()
    this.getUserSecurityQuestion()
  }
}
router.map(routerMap)
router.redirect({
  '*': 'security'
})
router.beforeEach(function ({ to, next }) {
  router.app.checkIsLogin()
  next()
})
router.start(App, 'body')
